<?php

namespace qore_base\cli;
use \qore\base\Controller;
use \qore\util\DocBlock;
use \Qore;

/**
 * @author Samuel Nogueira <samuel.nogueira.dev@gmail.com>
 */
abstract class CliController extends Controller {
	
	/**
	 * Returns available commands in an array with the format array(COMMAND => DESCRIPTION)
	 * @return array
	 */
	public function getCommands() {
		$commands = array();
		$docBlock = new DocBlock(get_class($this));
		foreach ($this->getAvailableActions() as $action) {
			$method = 'action'.ucfirst($action);
			$commands[$action] = $docBlock->getMethodComment($method);
		}
		return $commands;
	}
	
	public function actionIndex() {
		foreach ($this->getCommands() as $command => $description) {
			// skip this command
			if ($command == 'index') continue;
			
			$text .= "$command\t$description\n";
		}
		
		echo CliHelper::box(trim($text), array(
			'title' => Qore::t('qore', 'Available Commands'),
		));
	}
}
